
ITEM.isbase = true
ITEM.class = "base_building"
ITEM.label = "Base Weapon"
ITEM.description = "The base building item\nCould be used to make a working building..."
ITEM.weight = 1
ITEM.model = "models/Weapons/w_bugbait.mdl"
ITEM.icon = "wintersurvival/icon_bugbait"
ITEM.rotation = ITEM.rotation or 1

//Inventory

function ITEM:onInvSelect(pl)
	local GM = gmod.GetGamemode()
	local itemtab,inv = self:getDatTab(pl)
	if not itemtab then
		inv[self.class] = {}
		itemtab = inv[self.class]
	end
	itemtab.buildstage = 1
end

function ITEM:onInvUnSelect(pl)
	local GM = gmod.GetGamemode()
	local itemtab,inv = self:getDatTab(pl)
	if not itemtab then
		inv[self.class] = {}
		itemtab = inv[self.class]
	end
	
	itemtab.buildstage = 1
	GM:GhostBuilding(pl,"false")
end

function ITEM:onScroll(delta)
	self.rotation = self.rotation + (delta * 15)
	RunConsoleCommand("wsBuildAng",self.rotation)
	return true
end

//Weapon

function ITEM:onPrimary(pl)
	if CLIENT then
		return
	end
	local GM = gmod.GetGamemode()
	local itemtab,inv = GM.pldat[pl:UniqueID()][self.class]
	
	if itemtab.buildstage == 1 then
		GM:GhostBuilding(pl,self.class)
		itemtab.buildstage = 2
		
		return 0
	elseif itemtab.buildstage == 2 then
		local good = GM:BuildIt(pl,self.class)
		if good then
			GM:GhostBuilding(pl,"false")
			itemtab.buildstage = 1
			pl:WSGive(self.class,-1)
			
			//Play build sound
			return 1
		else
			//Play error sound
			return -1
		end
	end
end

function ITEM:onSecondary(pl)
	local GM = gmod.GetGamemode()
	local itemtab,inv = self:getDatTab(pl)
	if not itemtab then
		inv[self.class] = {}
		itemtab = inv[self.class]
	end
	
	itemtab.buildstage = 1
	GM:GhostBuilding(pl,"false")
end
